package com.ytjj.qmyx.users.model.response;

import com.ytjj.qmyx.users.model.Users;
import com.ytjj.qmyx.users.model.UsersInfo;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 用户基础信息
 *
 *
 * @version 1.0
 *
 */
@Data
@Accessors(chain = true)
public class UsersResponse implements Serializable {

    private Integer id;

    /**
     * 手机号
     *
     * @mbg.generated
     */
    private String tel;

    /**
     * 账号
     *
     * @mbg.generated
     */
    private String account;

    /**
     * 昵称
     *
     * @mbg.generated
     */
    private String nickname;

    /**
     * 小程序openid
     */
    private String openid;

    /**
     * 注册来源 android、ios、h5、wx
     *
     * @mbg.generated
     */
    private String source;


    private String token;

    /**
     * 用户状态 1 正常 2停用 3 未注册
     *
     * @mbg.generated
     */
    private Byte status;

    /**
     * 性别 0 男 1女
     *
     * @mbg.generated
     */
    private Integer sex;

    /**
     * 邮箱
     *
     * @mbg.generated
     */
    private String email;

    /**
     * 头像
     *
     * @mbg.generated
     */
    private String headImg;

    /**
     * 会员等级 1 普通会员
     *
     * @mbg.generated
     */
    private Byte memberLevel;

    /**
     * 积分
     *
     * @mbg.generated
     */
    private Integer score;

    /**
     * 任务积分
     */
    private Integer taskScore;

    /**
     * 总积分
     *
     * @mbg.generated
     */
    private Integer totalScore;

    /**
     * 帐号余额
     *
     * @mbg.generated
     */
    private BigDecimal money;

    /**
     * 冻结余额
     *
     * @mbg.generated
     */
    private BigDecimal lockMoney;

    /**
     * 账号总积累余额
     *
     * @mbg.generated
     */
    private BigDecimal totalMoney;

    /**
     * 积累佣金
     * 现在描述是可提现金额
     * @mbg.generated
     */
    private BigDecimal brokerageNum;

    /**
     * 关注总数
     *
     * @mbg.generated
     */
    private Integer follow;

    /**
     * 粉丝总数
     *
     * @mbg.generated
     */
    private Integer fans;

    /**
     * 渠道名字
     *
     * @mbg.generated
     */
    private String channel;

    /**
     * 邀请人
     *
     * @mbg.generated
     */
    private Integer inviterId;

    /**
     * 是否会员1:vip会员，0：不是vip会员
     *
     * @mbg.generated
     */
    private Byte isVip;

    /**
     * 获赞数
     *
     * @mbg.generated
     */
    private Integer praise;

    /**
     * 作品总数
     *
     * @mbg.generated
     */
    private Integer dynamicSum;

    /**
     * 分享成为vip数量
     *
     * @mbg.generated
     */
    private Integer vipSum;

    /**
     * 分享vip所得总佣金
     *
     * @mbg.generated
     */
    private Integer vipMoney;

    /**
     * 是否开通直播权限0否 1是
     *
     * @mbg.generated
     */
    private Byte isOpenLive;

    /**
     * 是否为假用户 0否 1是
     *
     * @mbg.generated
     */
    private Byte isZombie;

    /**
     * 注册时间
     *
     * @mbg.generated
     */
    private Date registerTime;

    /**
     * 注册ip
     *
     * @mbg.generated
     */
    private String registerIp;

    /**
     * 年龄段
     */
    private String ageStr;

    /**
     * 是否填写标签
     */
    private Byte labelFillFlag;

    /**
     * unionid
     */
    private String unionid;

//
//    /**
//     * 腾讯云直播 userSig
//     */
//    private String userSig;

    private String labelText;

    /**
     * 用户描述
     */
    private String userDesc;

    /**
     * 是否支付过
     */
    private Boolean isPayOrder;

    private Integer temporarySore;

    private Date temporarySoreTime;

    /**
     * 用户红包余额
     **/
    private BigDecimal activityMax;

    /**
     * 当天晚上过期时间
     */
    private Long beforeDawnTime;

    private BigDecimal sumBalance;

    /**
     * 已提现金额
     *
     * @mbg.generated
     */
    private BigDecimal brokeragedNum;

    /**
     * 已消费补贴金额
     */
    private BigDecimal useSubsidyAmount;
    /**
     * 消费补贴总金额
     */
    private BigDecimal subsidyAmountCount;

    /**
     * 是否绑定手机号  1-已绑定 0-未绑定
     */
    private Integer isBindTel;

    /**
     * 是否优质严选管
     * 只要有动态测评就是严选官
     */
    private Integer  isQuality;

    /**
     * 达人标志  1-是 0-否
     * 判断标准，有审核通过的测评
     */
    private Integer talentFlag;

    /**
     * 是否有支付记录
     * 0-没有  1-有
     */
    private Integer payFlag;

    /**
     * 初始积分
     */
    private Integer initScore;


    public UsersResponse(Users users, UsersInfo usersInfo){
        BeanUtils.copyProperties(usersInfo,this);
        this.unionid = users.getWxUnionid();
        this.openid = users.getWxOpenid();
        this.token = users.getToken();
        this.source = users.getSource();
        this.nickname = users.getNickname();
        this.tel = users.getTel();
        this.account = users.getAccount();
        this.id = users.getId();
        this.headImg = usersInfo.getHeadImg();
        this.sex = usersInfo.getSex();
        this.labelFillFlag = usersInfo.getLabelFillFlag();
        this.ageStr = usersInfo.getAgeStr();
        this.userDesc = usersInfo.getUserDesc();
        if (StringUtils.isEmpty(this.userDesc)) {
            this.userDesc = "这个人很懒，什么都没有写";
        }
        this.score = usersInfo.getScore();
        this.taskScore = usersInfo.getTaskScore();
        this.temporarySore = usersInfo.getTemporarySore();
        this.temporarySoreTime = usersInfo.getTemporarySoreTime();
        if(usersInfo.getTemporarySore() != null && usersInfo.getTemporarySoreTime()!=null) {
            long time = usersInfo.getTemporarySoreTime().getTime();
            if(System.currentTimeMillis() < time) {
                // this.score = this.score == null ? usersInfo.getTemporarySore() : this.score + usersInfo.getTemporarySore();
            }else {
                this.temporarySore = 0;
            }
        }
//        if(StringUtils.isEmpty(this.headImg)) {
//            this.headImg = "http://img.quanminyanxuan.com/service/dce07fb4f50742ee9a95fc243d8f1e38.png";
//        }
    }

    public UsersResponse(){}
}
